var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();

$CertusFormAjax.ajax('findLastModify',{"stepId":stepId},function (response) {
    var data = response.data.bgInfos;
    $$scope.projName = response.data.projName;

    if (data.modifyProName!=undefined){
        $$scope.proName = true;
        $$scope.oldProName = data.oldProName;
        $$scope.mproName = data.modifyProName;
    }
    if (data.xsUserName!=undefined){
        $$scope.xsUser = true;
        $$scope.oldXsUserName = data.oldXsUserName;
        $$scope.xsUserName = data.xsUserName+"("+data.xsUserId+")";
    }
    if (data.selUserName!=undefined){
        $$scope.selUser = true;
        $$scope.oldSelUserName = data.oldSelUserName;
        $$scope.xsUserName = data.xsUserName+"("+data.xsUserId+")";
    }
    if (data.mgUserName!=undefined){
        $$scope.mgUser = true;
        $$scope.oldMgUserName = data.oldMgUserName;
        $$scope.mgUserName = data.mgUserName+"("+data.mgUserId+")";
    }
    if (data.delUserName!=undefined){
        $$scope.delUser = true;
        $$scope.oldDelUserName = data.oldDelUserName;
        $$scope.delUserName = data.delUserName+"("+data.delUserId+")";
    }
    if (data.pduUserName!=undefined){
        $$scope.pduUser = true;
        $$scope.oldPduUserName = data.oldPduUserName;
        $$scope.pduUserName = data.pduUserName+"("+data.pduUserId+")";
    }
    if (data.modifyProState!=undefined){
        $$scope.proState = true;
        if (data.oldModifyProState=="1"){
            $$scope.oldModifyProState = "运行中";
        }else if (data.oldModifyProState=="2"){
            $$scope.oldModifyProState = "已关闭";
        }else if (data.oldModifyProState=="3"){
            $$scope.oldModifyProState = "已完结";
        }else if (data.oldModifyProState=="4"){
            $$scope.oldModifyProState = "已暂停";
        }

        if (data.modifyProState=="1"){
            $$scope.modifyProState = "运行中";
        }else if (data.modifyProState=="2"){
            $$scope.modifyProState = "已关闭";
        }else if (data.modifyProState=="3"){
            $$scope.modifyProState = "已完结";
        }else if (data.modifyProState=="4"){
            $$scope.modifyProState = "已暂停";
        }
    }

    if (data.modifyProLv!=undefined){
        $$scope.proLv = true;
        if (data.oldModifyProLv=="1"){
            $$scope.oldModifyProLv = "低";
        }else if (data.oldModifyProLv=="2"){
            $$scope.oldModifyProLv = "中";
        }else if (data.oldModifyProLv=="3"){
            $$scope.oldModifyProLv = "高";
        }

        if (data.modifyProLv=="1"){
            $$scope.modifyProLv = "低";
        }else if (data.modifyProLv=="2"){
            $$scope.modifyProLv = "中";
        }else if (data.modifyProLv=="3"){
            $$scope.modifyProLv = "高";
        }
    }

    if (data.modifyUrgency!=undefined){
        $$scope.urgency = true;
        if (data.oldModifyUrgency=="1"){
            $$scope.oldModifyUrgency = "紧急";
        }else if (data.oldModifyUrgency=="0"){
            $$scope.oldModifyUrgency = "不紧急";
        }

        if (data.modifyUrgency=="1"){
            $$scope.modifyUrgency = "紧急";
        }else if (data.modifyUrgency=="0"){
            $$scope.modifyUrgency = "不紧急";
        }
    }

    if (data.modifyImportance!=undefined){
        $$scope.importance = true;
        if (data.modifyImportance=="0"){
            $$scope.modifyImportance = "一般";
        }else if (data.modifyImportance=="1"){
            $$scope.modifyImportance = "重要";
        }else{
            $$scope.modifyImportance = "战略";
        }

        if (data.oldModifyImportance=="0"){
            $$scope.oldModifyImportance = "一般";
        }else if (data.oldModifyImportance=="1"){
            $$scope.oldModifyImportance = "重要";
        }else{
            $$scope.oldModifyImportance = "战略";
        }
    }

    if (data.proSignDate!=undefined){
        $$scope.signDate = true;
        $$scope.oldProSignDate = data.oldProSignDate;
        $$scope.proSignDate = data.proSignDate;
    }

    if (data.proHkDate!=undefined){
        $$scope.hkDate = true;
        $$scope.oldProHkDate = data.oldProHkDate;
        $$scope.proHkDate = data.proHkDate;
    }

    if (data.modifyEndTime!=undefined){
        $$scope.proTime = true;
        $$scope.modifyBeginTime = data.modifyBeginTime;
        $$scope.modifyEndTime = data.modifyEndTime;

        $$scope.oldModifyBeginTime = data.oldModifyBeginTime;
        $$scope.oldModifyEndTime = data.oldModifyEndTime;
    }

    if (data.selMoney!=undefined){
        $$scope.smoney = true;
        $$scope.oldSelMoney = data.oldSelMoney;
        $$scope.selMoney = data.selMoney;
    }

    if (data.ysMoney!=undefined){
        $$scope.ymoney = true;
        $$scope.oldYsMoney = data.oldYsMoney;
        $$scope.ysMoney = data.ysMoney;
    }

    if (data.modifyDeptId!=undefined){
        $$scope.deptId = true;
        $$scope.oldModifyDeptId = data.oldModifyDeptName;
        $$scope.modifyDeptId = data.modifyDeptName;
    }

    if (data.modifyArea!=undefined){
        $$scope.proArea = true;
        $$scope.oldModifyArea = data.oldModifyArea;
        $$scope.modifyArea = data.modifyArea;
    }

    if (data.modifyCusId!=undefined){
        $$scope.cusId = true;
        $$scope.oldModifyCusId = data.oldModifyCusName;
        $$scope.modifyCusId = data.modifyCusName;
    }

    if (data.modifyPdLine!=undefined){
        $$scope.pdLine = true;
        $$scope.oldModifyPdLine = data.oldModifyPdLineName;
        $$scope.modifyPdLine = data.modifyPdLineName;
    }

    if (data.modifyCompare!=undefined){
        $$scope.compare = true;
        if (data.oldModifyCompare==0){
            $$scope.oldModifyCompare = "无";
        }else{
            $$scope.oldModifyCompare = "有";
        }
        if (data.modifyCompare==0){
            $$scope.modifyCompare = "无";
        }else{
            $$scope.modifyCompare = "有";
        }
    }

    if (data.modifyClue!=undefined){
        $$scope.clues = true;
        $$scope.oldModifyClue = data.oldModifyClue;
        $$scope.modifyClue = data.modifyClue;
    }

    if (data.modifyCompetitor!=undefined){
        $$scope.ompetitor = true;
        $$scope.oldModifyCompetitor = data.oldModifyCompetitor;
        $$scope.modifyCompetitor = data.modifyCompetitor;
    }

    if (data.modifyCusPolicy!=undefined){
        $$scope.cusPolicy = true;
        $$scope.oldModifyCusPolicy = data.oldModifyCusPolicy;
        $$scope.modifyCusPolicy = data.modifyCusPolicy;
    }
    $$scope.changeMessage = data.changeMessage;
    $$scope.optionMsg = data.opinionMsg;
    $$scope.proId = data.projId;
    $$scope.id = data.id;
});

$(".submit").click(function () {
    // 开启
    var index = layer.load(1);
    $CertusFormAjax.ajax('approvalChange',{"processId":processId,"stepId":stepId,
        "message":$("#optionMsg").val(),"proId":$$scope.proId,"id":$$scope.id},function () {
        //关闭
        layer.close(index);
        layer.msg("审批成功");
        window.history.back();
    });
});

$(".unSubmit").click(function () {
    var param = {};
    param.stepId = stepId;
    param.processId = processId;
    param.id = $$scope.id;
    param.proId = $$scope.proId;
    param.message = $("#optionMsg").val();
    // 开启
    var index = layer.load(1);
    $CertusFormAjax.ajax('unAprChange',{"param":JSON.stringify(param)},function () {
        //关闭
        layer.close(index);
        layer.msg("审批成功");
        window.history.back();
    });
});